#define _CRT_SECURE_NO_WARNINGS 1
#include <cstdio>
#include <iostream>
using namespace std;

#include <iostream>
using namespace std;
int n;

int GetMonthDay(int year, int month)
{
    static int MonthDay[13] = { -1,31,28,31,30,31,30,31,31,30,31,30,31 };
    if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)))
    {
        return 29;
    }
    return MonthDay[month];
}
int main() {
    cin >> n;
    int year, day;
    int month = 1;
    while (n--)
    {
        cin >> year >> day;
        while (day > GetMonthDay(year, month))
        {
            int y = GetMonthDay(year, month);
            day -= y;
            month++;
            if (month == 13)
            {
                month = 1;
                year++;
            }
        }
        printf("%04d-%02d-%02d\n", year, month, day);
    }
    return 0;
}

//int n;
//int GetMonthDay(int year, int month)
//{
//    static int MonthDay[13] = { -1,31,28,31,30,31,30,31,31,30,31,30,31 };
//    if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)))
//    {
//        return 29;
//    }
//    return MonthDay[month];
//}
//int main() {
//    cin >> n;
//    int year, month, day;
//    int x;
//    while (n--)
//    {
//        cin >> year >> month >> day >> x;
//        day += x;
//        while (day > GetMonthDay(year, month))
//        {
//            int y = GetMonthDay(year, month);
//
//            day -= y;
//            month++;
//            if (month == 13)
//            {
//                month = 1;
//                year++;
//            }
//        }
//        printf("%04d-%02d-%02d", year, month, day);
//    }
//    return 0;
//}